#include "stdio.h"
#include "stdlib.h"

#define NUll 0

struct subject
{
    int subject_number;
    int score;
    struct subject *next;
};

struct subject * creat_chain_table(int n);
void input(struct subject *x);
void output(struct subject *y);
int find(struct subject *r,struct subject *i);
struct subject * insert(struct subject * z,struct subject *pi);

int main()
{
    int num;
    struct subject aim;
    struct subject *p=&aim,*head;
    scanf("%d",&num);
    head=creat_chain_table(num);
    input(head);
    scanf("%d",&(p->subject_number));
    if (find(head, p)) {
        insert(head, p);
    }
    output(head);
    return 0;
}

struct subject * creat_chain_table(int n)
{
    struct subject *head= NUll,*pf = NUll,*pb;
    for(int i=0;i<n;i++)
    {
        pb=(struct subject *)malloc(sizeof(struct subject));
        if(i==0)
        {
            pf=head=pb;
        }
        else
        {
            pf->next=pb;
        }
        pb->next=NULL;
        pf=pb;
    }
    return (head);
}

void input(struct subject *x)
{
    while (x!=NUll) {
        scanf("%d %d",&(x->subject_number),&(x->score));
        x=x->next;
    }
}

void output(struct subject *y)
{
    while (y!=NUll) {
        printf("%d %d\n",y->subject_number,y->score);
        y=y->next;
    }
}

int find(struct subject *r,struct subject *i)
{
    struct subject * pb;
    pb=r;
    while (pb!=NUll) {
        if(pb->subject_number==i->subject_number)
        {
            printf("%d\n",pb->score);
            break;
        }
        pb=pb->next;
    }
    if (pb==NUll) {
        return 1;
    }
    else
    {
        return 0;
    }
}

struct subject * insert(struct subject * z,struct subject *pi)
{
    struct subject *ppb;
    ppb=z;
    while (ppb->next!=NUll) {
        ppb=ppb->next;
    }
    ppb->next=pi;
    pi->next=NUll;
    return z;
}